import tkinter as tk

def m_mode(a):
    js = {}
    max = 1
    # 计算相同数字出现的数量
    for i in range(len(a)):
        s = a[i]
        if s in js:
            n = js[s] + 1
            js[s] = n
            if n > max:
                max += 1
        else:
            js[s] = 1
    # 寻找出现次数最多的数字
    for val in js:
        if js[val] == max:
            return val

def predict():
    s = data.get()
    arr = s.split()
    result = m_mode(arr)
    prediction_label.config(text='预计下次可以命中：' + result + "环")

# 创建主窗口
root = tk.Tk()
root.title("预测射击运动员下一次能命中几环")

# 创建输入框和预测按钮
data = tk.Entry(root)
data.insert(0,"8 9 10 9 7")
data.pack()
predict_button = tk.Button(root, text="预测", command=predict)
predict_button.pack()

# 创建结果显示标签
prediction_label = tk.Label(root, text="")
prediction_label.pack()

# 运行主循环
root.mainloop()